﻿/********************************************************************************************************************
* Author:	Aris Michail																							*
* Email:	std03055@di.uoa.gr																						*
* Purpose:	This script is used in order to create the stored procedure "usp_deleteAttributeFromCategory" that		*
*			deletes an attribute from a category.																	*
********************************************************************************************************************/

CREATE PROCEDURE [dbo].[usp_deleteAttributeFromCategory]
	@catid bigint,
	@attrname nvarchar(50)
AS
	DECLARE @attrid bigint

	SELECT @attrid = Attributes.ID										/* get the id of the attribute */
	FROM Attributes
	WHERE Attributes.Category = @catid and Attributes.Name = @attrname

	DELETE FROM [Entity-Attribute]										/* delete the attribute from the entities */
	WHERE [Entity-Attribute].Attribute = @attrid

	DELETE FROM Attributes												/* delete the attribute */
	WHERE Attributes.ID = @attrid

RETURN 0